import pandas as pd
import matplotlib.pyplot as plt

# Read CSV data from file
df = pd.read_csv("trade_records.csv")

# Convert date column to datetime
df['date'] = pd.to_datetime(df['date'])

# Create figure and axis
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 8), sharex=True)

# Plot price over time with different colors for BUY and SELL
for side, color in [('BUY', 'green'), ('SELL', 'red')]:
    mask = df['side'] == side
    ax1.scatter(df['date'][mask], df['price'][mask], c=color, label=side, s=100)
ax1.set_title('Stock Price Over Time')
ax1.set_ylabel('Price ($)')
ax1.grid(True)
ax1.legend()

# Plot shares over time with different colors for BUY and SELL
for side, color in [('BUY', 'green'), ('SELL', 'red')]:
    mask = df['side'] == side
    ax2.scatter(df['date'][mask], df['shares'][mask], c=color, label=side, s=100)
ax2.set_title('Shares Traded Over Time')
ax2.set_xlabel('Date')
ax2.set_ylabel('Shares')
ax2.grid(True)
ax2.legend()

# Rotate x-axis labels for better readability
plt.xticks(rotation=45)

# Adjust layout to prevent overlap
plt.tight_layout()

# Show plot
plt.show()